package c.e.a.c.l;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.GridView;
import android.widget.Scroller;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.m;
import androidx.recyclerview.widget.RecyclerView.q;
import androidx.recyclerview.widget.RecyclerView.w;
import b.i.k.o;
import b.p.b.u;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.datepicker.CalendarConstraints;
import com.google.android.material.datepicker.DateSelector;
import com.google.android.material.datepicker.Month;
import java.util.List;

/* compiled from: MaterialCalendar */
public final class d<S> extends q<S> {
    public static final /* synthetic */ int i0 = 0;
    public int X;
    public DateSelector<S> Y;
    public CalendarConstraints Z;
    public Month b0;
    public e c0;
    public b d0;
    public RecyclerView e0;
    public RecyclerView f0;
    public View g0;
    public View h0;

    /* compiled from: MaterialCalendar */
    public class a implements Runnable {
        public final /* synthetic */ int a;

        public a(int i) {
            this.a = i;
        }

        public void run() {
            RecyclerView recyclerView = d.this.f0;
            int i = this.a;
            if (!recyclerView.x) {
                m mVar = recyclerView.m;
                if (mVar == null) {
                    Log.e("RecyclerView", "Cannot smooth scroll without a LayoutManager set. Call setLayoutManager with a non-null argument.");
                } else {
                    mVar.X0(recyclerView, recyclerView.i0, i);
                }
            }
        }
    }

    /* compiled from: MaterialCalendar */
    public enum e {
        DAY,
        YEAR
    }

    /* compiled from: MaterialCalendar */
    public interface f {
    }

    /* compiled from: MaterialCalendar */
    public class b extends b.i.k.a {
        public b(d dVar) {
        }

        public void d(View view, b.i.k.y.b bVar) {
            this.a.onInitializeAccessibilityNodeInfo(view, bVar.a);
            bVar.i(null);
        }
    }

    /* compiled from: MaterialCalendar */
    public class d implements f {
    }

    /* compiled from: MaterialCalendar */
    public class c extends r {
        public final /* synthetic */ int G;

        public c(Context context, int i, boolean z, int i2) {
            this.G = i2;
            super(context, i, z);
        }

        public void a1(w wVar, int[] iArr) {
            if (this.G == 0) {
                iArr[0] = d.this.f0.getWidth();
                iArr[1] = d.this.f0.getWidth();
                return;
            }
            iArr[0] = d.this.f0.getHeight();
            iArr[1] = d.this.f0.getHeight();
        }
    }

    public void E(Bundle bundle) {
        super.E(bundle);
        if (bundle == null) {
            bundle = this.f;
        }
        this.X = bundle.getInt("THEME_RES_ID_KEY");
        this.Y = (DateSelector) bundle.getParcelable("GRID_SELECTOR_KEY");
        this.Z = (CalendarConstraints) bundle.getParcelable("CALENDAR_CONSTRAINTS_KEY");
        this.b0 = (Month) bundle.getParcelable("CURRENT_MONTH_KEY");
    }

    public View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        int i;
        int i2;
        Context contextThemeWrapper = new ContextThemeWrapper(k(), this.X);
        this.d0 = new b(contextThemeWrapper);
        layoutInflater = layoutInflater.cloneInContext(contextThemeWrapper);
        Month month = this.Z.a;
        if (l.q0(contextThemeWrapper)) {
            i = 2131493017;
            i2 = 1;
        } else {
            i = 2131493012;
            i2 = 0;
        }
        View inflate = layoutInflater.inflate(i, viewGroup, false);
        GridView gridView = (GridView) inflate.findViewById(2131296732);
        o.p(gridView, new b(this));
        gridView.setAdapter(new c());
        gridView.setNumColumns(month.e);
        gridView.setEnabled(false);
        this.f0 = (RecyclerView) inflate.findViewById(2131296735);
        this.f0.setLayoutManager(new c(k(), i2, false, i2));
        this.f0.setTag("MONTHS_VIEW_GROUP_TAG");
        o oVar = new o(contextThemeWrapper, this.Y, this.Z, new d());
        this.f0.setAdapter(oVar);
        int integer = contextThemeWrapper.getResources().getInteger(2131361807);
        RecyclerView recyclerView = (RecyclerView) inflate.findViewById(2131296738);
        this.e0 = recyclerView;
        if (recyclerView != null) {
            recyclerView.setHasFixedSize(true);
            this.e0.setLayoutManager(new GridLayoutManager(contextThemeWrapper, integer, 1, false));
            this.e0.setAdapter(new v(this));
            this.e0.g(new e(this));
        }
        if (inflate.findViewById(2131296722) != null) {
            MaterialButton materialButton = (MaterialButton) inflate.findViewById(2131296722);
            materialButton.setTag("SELECTOR_TOGGLE_TAG");
            o.p(materialButton, new f(this));
            MaterialButton materialButton2 = (MaterialButton) inflate.findViewById(2131296724);
            materialButton2.setTag("NAVIGATION_PREV_TAG");
            MaterialButton materialButton3 = (MaterialButton) inflate.findViewById(2131296723);
            materialButton3.setTag("NAVIGATION_NEXT_TAG");
            this.g0 = inflate.findViewById(2131296738);
            this.h0 = inflate.findViewById(2131296731);
            p0(e.DAY);
            materialButton.setText(this.b0.b);
            this.f0.h(new g(this, oVar, materialButton));
            materialButton.setOnClickListener(new h(this));
            materialButton3.setOnClickListener(new i(this, oVar));
            materialButton2.setOnClickListener(new j(this, oVar));
        }
        if (!l.q0(contextThemeWrapper)) {
            u uVar = new u();
            RecyclerView recyclerView2 = this.f0;
            RecyclerView recyclerView3 = uVar.a;
            if (recyclerView3 != recyclerView2) {
                if (recyclerView3 != null) {
                    q qVar = uVar.c;
                    List list = recyclerView3.k0;
                    if (list != null) {
                        list.remove(qVar);
                    }
                    uVar.a.setOnFlingListener(null);
                }
                uVar.a = recyclerView2;
                if (recyclerView2 != null) {
                    if (recyclerView2.getOnFlingListener() == null) {
                        uVar.a.h(uVar.c);
                        uVar.a.setOnFlingListener(uVar);
                        uVar.b = new Scroller(uVar.a.getContext(), new DecelerateInterpolator());
                        uVar.c();
                    } else {
                        throw new IllegalStateException("An instance of OnFlingListener already set.");
                    }
                }
            }
        }
        this.f0.k0(oVar.i(this.b0));
        return inflate;
    }

    public void Q(Bundle bundle) {
        bundle.putInt("THEME_RES_ID_KEY", this.X);
        bundle.putParcelable("GRID_SELECTOR_KEY", this.Y);
        bundle.putParcelable("CALENDAR_CONSTRAINTS_KEY", this.Z);
        bundle.putParcelable("CURRENT_MONTH_KEY", this.b0);
    }

    public LinearLayoutManager m0() {
        return (LinearLayoutManager) this.f0.getLayoutManager();
    }

    public final void n0(int i) {
        this.f0.post(new a(i));
    }

    public void o0(Month month) {
        o oVar = (o) this.f0.getAdapter();
        int d = oVar.c.a.d(month);
        int i = d - oVar.i(this.b0);
        Object obj = 1;
        Object obj2 = Math.abs(i) > 3 ? 1 : null;
        if (i <= 0) {
            obj = null;
        }
        this.b0 = month;
        if (obj2 != null && obj != null) {
            this.f0.k0(d - 3);
            n0(d);
        } else if (obj2 != null) {
            this.f0.k0(d + 3);
            n0(d);
        } else {
            n0(d);
        }
    }

    public void p0(e eVar) {
        this.c0 = eVar;
        if (eVar == e.YEAR) {
            this.e0.getLayoutManager().N0(((v) this.e0.getAdapter()).h(this.b0.d));
            this.g0.setVisibility(0);
            this.h0.setVisibility(8);
        } else if (eVar == e.DAY) {
            this.g0.setVisibility(8);
            this.h0.setVisibility(0);
            o0(this.b0);
        }
    }
}
